<?php

namespace App\Http\Controllers;

use App\Http\Requests\RegisterPost;
use Illuminate\Foundation\Http\FormRequest;

class IndexController extends Controller
{
//    //
//    public function index(Request $request, $id)
//    {
////        return view('welcome');
////        echo  $request->route()->named('index') . '</br>'; //判单当前路由是不是index 返回 0 或 1
//        echo $request->route()->getActionName();
////        return "id" . $id . route('index',['id' => $id]);
//
//    }
//
//    public function login(Request $request)
//    {
//       if ($request->getMethod()==="POST"){
//            if ($request->hasAny(['account','password'])){
//               $result = DB::table('users')->where('account',$request->input('account'))->first();
//               if ($result!=null&&$result->password == $request["password"]){
////                    return ResponseFactory::simpleResponse(true,"登录成功");
//                   if (!$token = auth('api')->attempt($request->only(['account','password']))) {
//                       return response()->json(['error' => 'Unauthorized'], 401);
//                   }
////获取Token
//                   return ResponseFactory::response($token);
//               }else{
//                   return ResponseFactory::simpleResponse(false,"登录失败");
//               }
//
//            }else{
//                return ResponseFactory::simpleResponse(false,"缺少用户名和密码");
//            }
//           $credentials = request(['account', 'password']);
//
//           if (!$token = auth('api')->attempt($credentials)) {
//               return response()->json(['error' => 'Unauthorized'], 401);
//           }
////获取Token
//           return ResponseFactory::response($token);
//       }else{
//           $date = date("y-m-d H:i:s",time());
//           $message = "这是一个变量";
////        return \view('user.login',['date'=>$date]);
//           $time = time();
//           $users = DB::table('users')->offset(10)->limit(5)->get();
////        $users = [];
//           return \view('user.login',compact('date','message','time','users'));
//       }
//    }
//
//
//
//    public function register(RegisterPost $request): array
//    {
////        $credentials = [
////            'account' => $request->account,
////            'password' => Hash::make($request->password),
////            'nickName' => $request->nickName,
////            'email' => $request->email,
////            'tel' => $request->tel,
////        ];
////        $user = User::create($credentials);
//        $validated = $request->validated();
//        return ResponseFactory::simpleResponse(true,"操作成功");
//    }
//
//    public function getUserMessage(Request $request)
//    {
////        $result = DB::table('users')->find(2);
////        offect() 从什么地方开始
////        limit()  限制输出的个数
//        $result = DB::table('users')->offset(25)->limit(5)->orderBy('age','desc')->get();
//        return ResponseFactory::response($result);
//
//    }
//
//
//    public function changeUser(Request $request): array
//    {
//        if ($request->hasAny(['account', 'password', 'nickName', 'email', 'tel'])) {
////            检测数据库中是否有数据重复
////            返回结果为受到影响的行数
//            $result = DB::table("users")->where('account', $request->input("account"))->update($request->all());
//            if ($result > 0) {
//                return ResponseFactory::response();
//            } else {
//                return ResponseFactory::response(null, null, 200, "修改失败");
//            }
//        } else {
//            return ResponseFactory::response(null, null, 200, "字段不完整");
//        }
//
//    }
//
//    public function delete(Request $request): array
//    {
//        if (DB::table("users")->find($request->input("id")) != null) {
//            $result = DB::table('users')->where('id', '=', $request->input('id'))->delete();
//        } else {
//            return ResponseFactory::simpleResponse(false, "没有这个用户");
//        }
//        return $result > 0 ? ResponseFactory::simpleResponse(true, "删除成功") : ResponseFactory::simpleResponse(false, "删除成功");
//    }


    function send(RegisterPost $registerPost)
    {
        $validated = $registerPost->validated();
        return response()->json($validated);
    }
}
